
/*
   Tank with ESP32: components
*/

#ifndef COMPONENTS_H
#define COMPONENTS_H

#include "component_btn7919.h"
#include "component_ultrasonic.h"
#include "component_ir_avoidance.h"
#include "component_dht11.h"
// #include "component_ssd1306.h"
#include "component_lcd1602a_i2c.h"
#include "component_servo.h"
// #include "component_led.h"

String json;
bool data_ready = false;

void setup_components()
{
  Serial.begin(9600);
  setup_btn7919();
  setup_ultrasonic();
  setup_ir_avoidance();
  setup_dht11();
  // setup_ssd1306();
  setup_lcd1602a_i2c();
  setup_servo();
  // setup_led();
}

void loop_components()
{
  loop_dht11();
  loop_ultrasonic();
  loop_ir_avoidance();
  // loop_ssd1306();
  loop_lcd1602a_i2c();
  // loop_led();
  json = "{";
  json += "\"distance\":" + String(distance, 2);
  json += ",\"left_speed_pwm\":" + String(left_speed);
  json += ",\"right_speed_pwm\":" + String(right_speed);
  json += ",\"temperature\":" + String(temperature, 2);
  json += ",\"humidity\":" + String(humidity, 2);
  json += "}";
  data_ready = true;
}

#endif /* COMPONENTS_H */
